package org.example;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;

public class MyBatisXmlParse {
    public void parse() throws IOException {
        Document doc = Jsoup.parse(new File("D:\\git store\\ycdemo-maven\\maven\\src\\main\\resources\\mybatis.xml"),
                "utf-8");

        //返回一组元素
        Elements environments = doc.getElementsByTag("environments");
        if (environments.isEmpty()) {
            return;
        }
        
        //返回一个元素
        Element element = environments.get(0);

        String aDefault = element.attr("default");

        Element environment = doc.getElementById(aDefault);
        Elements propertys = environment.getElementsByTag("property");

        for (Element property : propertys) {
            String name = property.attr("name");
            String value = property.attr("value");
            System.out.printf(name + "=" + value + "\n");


        }
        

    }


}
